package app.server.project.main.service.db.entity.user;

import app.server.project.core.constants.Def;
import app.server.project.main.service.service.upay.tron.constants.TxStatus;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.Data;
import org.hibernate.annotations.Comment;

import java.time.LocalDateTime;

@Data
@Entity(name = "block_transaction")
@TableName("block_transaction")
@Comment(value = "区块交易记录")
public class BlockTransactionEntity {

    @Id
    @Column(name = "id")
    @Comment("用户主键")
    @TableId("id")
    private long id;


    @TableField("transaction_id")
    @Column(name = "transaction_id")
    @Comment("交易id")
    private String transactionId;

    @TableField("block_type")
    @Column(name = "block_type")
    @Comment("区块类型")
    private int blockType;

    @TableField("add_flag")
    @Column(name = "add_flag")
    @Comment("余额添加处理标记")
    private int addFlag;

    @TableField("amount")
    @Column(name = "amount")
    @Comment("充值金额")
    private long amount;

    @TableField("user_id")
    @Column(name = "user_id")
    @Comment("用户id")
    private long userId;

    @TableField("transfer_tx_id")
    @Column(name = "transfer_tx_id")
    @Comment("批量转账id")
    private String transferTxId;

    @Column(name = "create_time")
    @Comment("备注")
    @TableField("create_time")
    private LocalDateTime createTime;

    @TableField("tx_flag")
    @Comment("交易标记")
    @Column(name = "tx_flag")
    private int TxFlag;

    public static BlockTransactionEntity of(String transactionId, long userId, long amount, int blockType) {
        BlockTransactionEntity userInfoEntity = new BlockTransactionEntity();
        userInfoEntity.setId(IdUtil.getSnowflakeNextId());
        userInfoEntity.setBlockType(blockType);
        userInfoEntity.setTransactionId(transactionId);
        userInfoEntity.setAmount(amount);
        userInfoEntity.setAddFlag(Def.FALSE);
        userInfoEntity.setUserId(userId);
        userInfoEntity.setTxFlag(TxStatus.Init);
        userInfoEntity.setCreateTime(LocalDateTime.now());
        return userInfoEntity;
    }


    public boolean isAdd() {
        return this.addFlag >= 1;
    }


}
